package com.lh.blog.domain.entity;

import org.jetbrains.annotations.NotNull;

/**
 * @Author: Hang Luo
 * @Date: 2023/7/6-12:18
 * @Descript:
 * 返回统一标准  '{ code: 1, msg : '成功' , data : 对象（map/list/object） }'
 * code: 0, msg : '失败原因'
 *
 *  如果包含分页数据 data统一map格式
 *  { code: 1, msg : '成功' , data : { pageSize : int, currPage : int, data : 数组或者list } }
 *
 *  包含多对象数据 统一map格式
 *  { code: 1, msg : '成功' , data : { user : user , articleList : list , article : article } }
 **/
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;

    public ResponseResult() {
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static @NotNull ResponseResult<Object> ResponseResultSuccess() {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.code = 1;
        responseResult.msg = "成功";
        return responseResult;
    }

    public static @NotNull ResponseResult<Object> ResponseResultFail() {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.code = 0;
        return responseResult;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
